import { request } from "../utils/index.js"
export default {
    create: Cinemas =>
        new Promise(resolve => {
            $.ajax({
                type: "post",
                url: "/api/cinemas",
                data: Cinemas,
                success: resolve
            })

        }),
    get: async ({ curpage = 1, eachPage = 10 } = {}) => {
        return await request({
            url: "/api/cinemas",
            type: "GET",
            data: { curpage, eachPage }
        });
    },
    xiu: (_id, name, phone, address, status) => 
        request({
            type: "PATCH",
            url: "/api/cinemas/xiu",
            data: { _id, name, phone, address, status},
        })
    ,
    shan: (_id, name, phone, address, status, imgs) => {
        request({
            type: "DELETE",
            url: "/api/cinemas/shan",
            data: { _id, name, phone, address, status, imgs },
        })
    },
    searchcinemas: (name, address, status) =>
        request({
            type: "POST",
            url: `/api/cinemas/searchCinemas`,
            data: { name, address, status },
        })
    ,
    deleteimg: ({ _id, url }) =>
        request({
            type: "DELETE",
            url: `/api/cinemas/${_id}/imgs/${encodeURIComponent(url)}`,
        }),
    getOne: _id =>
        request({
            url: `/api/cinemas/${_id}`,
            type: "GET",
        }),
}